<?php
////
///
//	String

function JO_string_textArray( $text, $assign = ":", $separate = ";" ) {
	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///

	if( ! $text ) return null;

	if( strpos( $text, $separate ) == false && strpos( $text, $assign ) == false ) return array( trim( $text ) );

	$sentence = explode( $separate, $text );

	foreach( $sentence as $key => $value ) {

		if( ! $value ) continue;

		if( strpos( $value, $assign ) == false ) {

			$result[ $key ] = trim( $value );

		} else {

			$word = explode( $assign, $value );

			if( $word[ 0 ] ) $result[ trim( $word[ 0 ] ) ] = trim( $word[ 1 ] );

		}

	}

	return $result;

} function JO_textArray( $text, $assign = ":", $separate = ";" ) {
	return JO_string_textArray( $text, $assign, $separate );
}



function JO_string_date( $date, $class = "JO_gray_40" ) {
	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///

	global $JO_language;

	switch( $JO_language ) {

		case "EN":	return substr( $date, 5, 2 ) . "<span class='" . $class . "'>/</span>" . substr( $date, 8, 2 ) . "<span class='" . $class . "'>/</span>" . substr( $date, 0, 4 );
		case "KO":	return substr( $date, 0, 4 ) . "<span class='" . $class . "'>-</span>" . substr( $date, 5, 2 ) . "<span class='" . $class . "'>-</span>" . substr( $date, 8, 2 );
		case "VI":	return substr( $date, 8, 2 ) . "<span class='" . $class . "'>/</span>" . substr( $date, 5, 2 ) . "<span class='" . $class . "'>/</span>" . substr( $date, 0, 4 );
		default:	return substr( $date, 0, 4 ) . "<span class='" . $class . "'>-</span>" . substr( $date, 5, 2 ) . "<span class='" . $class . "'>-</span>" . substr( $date, 8, 2 );

	}

} function JO_date( $date, $class = "JO_gray_40" ) {
	return JO_string_date( $date, $class );
}



////
///
//	JavaScript

function JO_JS_location( $URL = false ) {
	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///


	if( $URL )	exit( "<script> try { parent.location.replace ( '" . $URL .		"'						); } catch ( exception ) { location.replace( '" . $URL . "'							); } </script>" );
	else		exit( "<script> try { parent.location.replace ( '" . $_SERVER[ "HTTP_REFERER" ] . "'	); } catch ( exception ) { location.replace( '" . $_SERVER[ "HTTP_REFERER" ] . "'	); } </script>" );

} function JO_location( $URL = false ) {
	JO_JS_location( $URL );
}



function JO_JS_innerHTM( $object, $content, $class = null ) {
	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///

	if( $class )	echo "<script> parent.document.getElementById( '" . $object . "' ).setAttribute( 'class', '" . $class . "' );	</script>";
	echo "<script> parent.document.getElementById( '" . $object . "' ).innerHTML = \"" . $content . "\";			</script>";

} function JO_innerHTM( $object, $content, $class = null ) {
	JO_JS_innerHTM( $object, $content, $class );
}



////
///
//	Session

function JO_session( ) {
	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///

	$_SESSION[ $_REQUEST[ "JO_session_key" ] ] = $_REQUEST[ "JO_session_value" ];

	echo "<b>Asynchronous</b> : \$_SESSION[ '" . $_REQUEST[ "JO_session_key" ] . "' ] = '" . $_REQUEST[ "JO_session_value" ] . "';";

}



////
///
//	Language

function JO_language( $value ) {
	/// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///

	//global $JO_language;

	$language = isset($_SESSION["lang"])?$_SESSION["lang"]:"VI";

	if( is_array( $value ) ) {

		return $value[ $language ];

	} else {

		if( strpos( $value, "{" . $language . "}" ) === false ) {

			if( strpos( $value, "{EN}" ) === false ) return $value;
			else									$language = "EN";

		}

		$temp = explode( "{"	. $language . "}", $value		);
		$temp = explode( "{/"	. $language . "}", $temp[ 1 ]	);

		return $temp[ 0 ];

	}

} function JO( $array ) {
	return JO_language( $array );
}

/*
 * =============================================== Tuan Area ===============================================
 */
	/*
	 * limit amount of words of paragraph
	 * Author			: Internet
	 * Crreated Date	: 24/08/2011
	 * Modified Date	: 24/08/2011
	 */
	function limit_text($text,$maxlen){
                if($text==null) return "";
		$sentenceSymbol=array(".","!","?"," ",",");  // Position of sentence
		$text=strip_tags($text,"<br /><br/><br><b><i>"); // tags for ending sentence
		for ($i=$maxlen; $i>0; $i--)  {
			$ch=substr($text,$i,1);
			if (in_array($ch,$sentenceSymbol)){
				$pos=$i;
				$i=0;
			}
		}
		$temp=substr($text,0,$pos+1);
		return $temp;
	}
/*
 * =============================================== End Tuan Area ===============================================
 */


function convertHTMLentities_($_string,$_quote_style){
     $_string = stripslashes($_string);
//            switch ($_quote_style) {
//                case 'quotes':
//                    $_quote_style = ENT_QUOTES;
//                    break;
//                case 'noquotes':
//                    $_quote_style = ENT_NOQUOTES;
//                    break;
//                case 'compat':
//                default:
//                    $_quote_style = ENT_COMPAT;
//                    break;
//            }


            //return htmlentities($_string, ENT_QUOTES,'utf-8');//
            return htmlentities(htmlentities($_string, ENT_QUOTES,'utf-8'), ENT_QUOTES,'utf-8');
}
function JO_convertHTMLentities($_string){
    return convertHTMLentities_($_string,"ENT_QUOTES");
}



function JO_UNconvertHTMLentities($_string){
   return str_replace("59d7d64dbcc254544f04cdb81ccff699", "<br/>",str_replace("  ", "&nbsp;&nbsp;",html_entity_decode($_string, ENT_QUOTES,'utf-8')));
   
}

function getString($_s){
    return isset($_s)?$_s:"[data is empty]";
}
function getstringhtml($_text){
    return str_replace("\"", "&quot;",$_text);
}
function setstringhtml($_text){
    return str_replace("\"", "\\\"",str_replace("'", "\'",$_text));
}
?>